port module Main exposing (..)

import Html exposing (Html, div, text, program)
import Html.Attributes exposing (class,id,style)
import Http
import Json.Decode as Decode
import Model exposing (..)
import Page2.View as P2
import Page3.View as P3
import Page4.View as P4
import Page5.View as P5


init : ( Model_result, Cmd Msg )
init = (Decode.decodeString model_decoder mock_data, elm_loaded ())


-- MESSAGES


type Msg
    = OnFetched (Result Http.Error (Model_result))
    | NoOp



-- VIEW


view : Model_result -> Html Msg
view result =
    case result of
        Err error -> div [] [ text error ]
    
        Ok model -> div 
                      [id "fullpage"] 
                      [ div 
                          [ class "section" ]
                          [ div 
                              [id "page1"
                              ,class "page"
                              ,class "slide"
                              ] 
                              [div
                                 [class "container"
                                 ,style [("width","85%")]]
                                 [Html.h1 [] [text ((.page1 >> .name) model)]
                                 ,Html.p [class "lead"] [text ((.page1 >> .desc) model)]
                                 ]
                              ]
                          , Html.map (\_ -> NoOp) (P2.view (.page2 model))
                          , Html.map (\_ -> NoOp) (P3.view (.page3 model))
                          , Html.map (\_ -> NoOp) (P4.view (.page4 model))
                          , Html.map (\_ -> NoOp) (P5.view (.page5 model))
                          ]
                      ]


-- UPDATE


update : Msg -> Model_result -> ( Model_result, Cmd Msg )
update msg model =
    case msg of
        NoOp ->
            (model, Cmd.none)

        OnFetched (Ok newModel) ->
            (newModel, Cmd.none)

        OnFetched (Err error) ->
            (model, Cmd.none)



-- SUBSCRIPTIONS


subscriptions : Model_result -> Sub Msg
subscriptions model =
    Sub.none


-- COMMAND

-- fetchHome : Cmd Msg
-- fetchHome =
--    Http.get "http://localhost:3000/home.json" myDecoder


-- myDecoder : Decode.Decoder Model
-- myDecoder =
--    Pip.decode Model

-- PORT
port elm_loaded : () -> Cmd msg


-- MAIN


main : Program Never Model_result Msg
main =
    program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }